package com.qidianit.mes.sys.controller;

import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.Supplier;
import com.qidianit.mes.sys.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ Description:
 * @ Author:WuJingLei
 * @ Date: 2025/9/16 -20:11
 */
@RestController
@RequestMapping("/supplier")
public class SupplierController {
    @Autowired
    private SupplierService service;

    @GetMapping("/page")
    public Result<PageInfo<Supplier>> page(Supplier supplier,
                                           @RequestParam(defaultValue ="1")int pageNum,
                                           @RequestParam(defaultValue = "10")int size){
        return service.querySupplier(supplier,pageNum,size);
    }

    @GetMapping("/code/{code}")
    public Result<Supplier> queryByCode(@PathVariable String code){
        return service.queryByCode(code);
    }

    @PostMapping("/add")
    public Result<Supplier> add(@RequestBody Supplier supplier){
        return service.saveSupplier(supplier);
    }

    @PutMapping("/update")
    public Result update(@RequestBody Supplier supplier){
        return service.updateSupplier(supplier);
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id){
        return service.deleteSupplier(id);
    }

    @DeleteMapping("/batchDelete")
    public Result batchDelete(Long[] id){
        return service.batchDelete(id);
    }
}
